package com.example.controller;

import com.example.entity.Student;
import com.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/add/{name}/{gender}/{classname1}")
    public void addStudent( @PathVariable String name, @PathVariable String gender,
                           @PathVariable String classname1) {
        Student student = new Student();
//        student.setNum(num);
        student.setName(name);
        student.setGender(gender);
        student.setClassname1(classname1);
        studentService.insert(student);
    }

    @GetMapping("/delete/{num}")
    public void deleteStudentByNum(@PathVariable Long num) {
        studentService.deleteByNum(num);
    }

    @GetMapping("/update/{num}/{name}/{gender}/{classname1}")
    public void updateStudent(@PathVariable Long num, @PathVariable String name, @PathVariable String gender,
                              @PathVariable String classname1){
        Student student = new Student();
        student.setNum(num);
        student.setName(name);
        student.setGender(gender);
        student.setClassname1(classname1);
        studentService.update(student);
    }

    @GetMapping("/get/{num}")
    public Student getStudentByNum(@PathVariable Long num) {
        return studentService.findByNum(num);
    }


}
